package com.igoal.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.igoal.dto.UserDTO;
import com.igoal.service.UserManagerExt;
import com.igoal.web.model.BaseModel;

@Controller
public class RegisterStepController extends BaseController{
	@Autowired
	public void setUserManagerExt(UserManagerExt userManagerExt) {
		this.userManagerExt = userManagerExt;
	}
	
	public String getViewPrefix() {
		return BaseControllerDelegate.DEFAULT_VIEW_PREFIX;
	}
	
	@RequestMapping("/findfriend.html")	
	public String execute(ModelMap modelMap){
		String userSession = getUserInSession();
		modelMap.addAttribute("userSession", userSession);
		
		initModel(userSession, modelMap);
		
		return getViewPrefix() + "registerStep";
	}	
	
	@RequestMapping("/welcome.html")
	public String firstVisit(ModelMap modelMap){
		String userSession = getUserInSession();
		modelMap.addAttribute("userSession", userSession);
		modelMap.addAttribute("welcome", "welcome");
		
		initModel(userSession, modelMap);
		
		return getViewPrefix() + "registerStep";
	}
	
	public void initModel(String userSession, ModelMap modelMap){
		UserDTO user = getUserSession();
		Long[] categoryIds = user.getCategoryIds();
		if(categoryIds != null){
			String selected = "selected";
			for(Long categoryId : categoryIds){
				modelMap.addAttribute(selected+categoryId, categoryId);
			}
		}		
	}

	public void initTopPage(BaseModel model, HttpServletRequest request) {}

	public void initRightPage(BaseModel model, HttpServletRequest request) {}

	public void initLeftPage(BaseModel model, HttpServletRequest request) {}
}
